package com.qch.rabbitmq.demo;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;

import java.io.UnsupportedEncodingException;

/**
 * @Author qch
 * @Date 2021/5/14
 * ChannelAwareMessageListener
 * 或者使用implements MessageListener
 */
public class MyMessageListener implements ChannelAwareMessageListener{
    public void onMessage(Message message, Channel channel) throws Exception {
        System.out.println(new String(message.getBody(),message.getMessageProperties().getContentEncoding()));

    }
}
/*public class MyMessageListener implements MessageListener {
    public void onMessage(Message message) {
        try {
            System.out.println(new String(message.getBody(),message.getMessageProperties().getContentEncoding()));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }

}*/
